package com.anyonavinfo.cpaddemo.view.mainview.minimusicplayer;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
<<<<<<< HEAD
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.anyonavinfo.cpaddemo.MainActivity;
import com.anyonavinfo.cpaddemo.R;
import com.anyonavinfo.cpaddemo.data.musicinfo.MusicInfo;
import com.anyonavinfo.cpaddemo.data.musicinfo.source.MusicInfoRepository;
import com.anyonavinfo.cpaddemo.utils.ToastManagerUtils;
import com.anyonavinfo.cpaddemo.view.widget.circleimage.RoundImageView;



=======
import android.widget.LinearLayout;
import android.widget.TextView;

import com.anyonavinfo.cpaddemo.R;
import com.anyonavinfo.cpaddemo.data.musicinfo.source.MusicInfoRepository;
import com.anyonavinfo.cpaddemo.data.musicinfo.source.local.MusicInfoLocalDataSource;
import com.anyonavinfo.cpaddemo.utils.ToastManagerUtil;
import com.anyonavinfo.cpaddemo.view.widget.circleimage.RoundImageView;


>>>>>>> b56716b621890f59100a220d4c7abe0ddb29e232
/**
 * Created by ZuiC on 2017/1/16.
 */

<<<<<<< HEAD
public class MiniMusicPlayerView extends LinearLayout implements MiniMusicPlayerContract.View{
=======
public class MiniMusicPlayerView extends LinearLayout implements MiniMusicPlayerContract.View, View.OnClickListener {
>>>>>>> b56716b621890f59100a220d4c7abe0ddb29e232

    private Context mContext;
    private MiniMusicPlayerContract.Presenter mPresenter;

    private LinearLayout llMusicinfo;
<<<<<<< HEAD
    private ImageButton imgPrevois,imgNext,imgPlayPause,imgMode;
    private RoundImageView rivDisk;
    private TextView tvSongname,tvArtist;
    private ImageView ivOpenMusicPlayerView;
=======
    private ImageButton imgPrevois,imgNext,imgPlayPause;
    private RoundImageView rivDisk;
    private TextView tvSongname,tvArtist;
>>>>>>> b56716b621890f59100a220d4c7abe0ddb29e232
    private String TAG = "MiniMusicPlayerView";

    public MiniMusicPlayerView(Context context) {
        super(context);
        initView(context);
    }

    public MiniMusicPlayerView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public MiniMusicPlayerView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context){
        this.mContext = context;
        LayoutInflater layoutInflater = LayoutInflater.from(mContext);
        View view = layoutInflater.inflate(R.layout.view_mainview_minimusic_minimusicview, this);
        imgNext = (ImageButton) view.findViewById(R.id.img_next);
        imgPrevois = (ImageButton) view.findViewById(R.id.img_previous);
        imgPlayPause = (ImageButton) view.findViewById(R.id.img_playpause);
        llMusicinfo = (LinearLayout) view.findViewById(R.id.ll_musicinfo);
        rivDisk = (RoundImageView) view.findViewById(R.id.riv_disk);
        tvSongname = (TextView) view.findViewById(R.id.tv_songname);
        tvArtist = (TextView) view.findViewById(R.id.tv_artist);
<<<<<<< HEAD
        imgMode = (ImageButton) view.findViewById(R.id.img_mode);
        ivOpenMusicPlayerView = (ImageView) view.findViewById(R.id.iv_open_musicplayer);

        new MiniMusicPlayerPresenter(this, MusicInfoRepository.getInstance()).start();
=======
        new MiniMusicPlayerPresenter(this, MusicInfoRepository.getInstance(MusicInfoLocalDataSource.getInstance())).start();
>>>>>>> b56716b621890f59100a220d4c7abe0ddb29e232
        setListeners();
    }

    @Override
    public void setPresenter(MiniMusicPlayerContract.Presenter presenter) {
        mPresenter = presenter;
    }

<<<<<<< HEAD

    private void setListeners() {
        imgNext.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mPresenter.playNextMusic();
            }
        });

        imgPrevois.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mPresenter.playPreviousMusic();
            }
        });

        imgPlayPause.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mPresenter.playStopCurMusic();
            }
        });

        imgMode.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mPresenter.changePlayMode();
            }
        });

        ivOpenMusicPlayerView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {mPresenter.openMusicPlayerView();
            }
        });

    }

    @Override
    public void updateMusicInfo(MusicInfo musicInfo) {
        tvSongname.setText(musicInfo.getTitle());
        tvArtist.setText(musicInfo.getArtist());
    }

    @Override
    public void updatePlayMode(int playMode) {

        if (playMode == 0){
            imgMode.setImageResource(R.drawable.icon_musicplayer_orderplay);
            ToastManagerUtils.getInstance().showTextToast(mContext,"顺序播放");
        }
        if (playMode == 1){
            imgMode.setImageResource(R.drawable.icon_musicplayer_randomplay);
            ToastManagerUtils.getInstance().showTextToast(mContext,"随机播放");
        }
        if (playMode == 2){
            imgMode.setImageResource(R.drawable.icon_musicplayer_singlecycle);
            ToastManagerUtils.getInstance().showTextToast(mContext,"单曲循环");
        }

    }

    @Override
    public void updatePlayStatus(int playStatus) {
        if (playStatus == 0){
            imgPlayPause.setSelected(false);
        }else {
            imgPlayPause.setSelected(true);
        }
    }

    @Override
    public void showMusicPlayerView() {
        ((MainActivity)mContext).showMusicPlayerView();
    }

    public void onRedisplay(){
        mPresenter.refreshView();
=======
    private void setListeners() {
        imgNext.setOnClickListener(this);
        imgPrevois.setOnClickListener(this);
        imgPlayPause.setOnClickListener(this);
        llMusicinfo.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.ll_musicinfo:
                //转调音乐界面
                ToastManagerUtil.getInstance().showTextToast(mContext,"测试转调范围");
                break;
            case R.id.img_next:
                mPresenter.next();
                break;
            case R.id.img_playpause:
                if (mPresenter.isPlaying()) {
                    mPresenter.pause();
                }else {
                    mPresenter.play();
                }
                break;
            case R.id.img_previous:
                mPresenter.previous();
                break;
        }
        imgPlayPause.setSelected(mPresenter.isPlaying());
    }

    public void onMusicInfoResume() {
//        imgPlayPause.setSelected(mPresenter.isPlaying());
        imgPlayPause.setSelected(true);

>>>>>>> b56716b621890f59100a220d4c7abe0ddb29e232
    }
}
